package com.mufeng.libs.base

import android.content.Context
import android.content.res.Resources
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.viewbinding.ViewBinding
import com.blankj.utilcode.util.LanguageUtils
import com.gyf.immersionbar.ktx.immersionBar
import com.haoshuang.zhouzhoubang.R
import com.lnkj.jialubao.utils.AccountUtils

abstract class BaseVMActivity<VM: BaseViewModel, VB: ViewBinding>: BaseActivity<VM, VB>(){

    // 设置字体大小
    private var fontSize = 1.0f

    var p = 1
    var isShowing = true
    lateinit var mActivity: AppCompatActivity
    // 门店id
    val team_id = AccountUtils.user?.team_id.toString()

    /**
     * 修改字体大小
     * @return Resources
     */
    override fun getResources(): Resources {
        val resources = super.getResources()
        val configuration = resources.configuration
        configuration.fontScale = fontSize
        configuration.densityDpi = (applicationContext.resources.displayMetrics.densityDpi * fontSize).toInt()
        resources.updateConfiguration(configuration, resources.displayMetrics)
        return resources
    }

    override fun attachBaseContext(newBase: Context?) {
        super.attachBaseContext(LanguageUtils.attachBaseContext(newBase))
    }


    override fun onCreate(savedInstanceState: Bundle?) {
        mActivity = this
        super.onCreate(savedInstanceState)
    }

    override fun initImmersionBar() {
        immersionBar {
            statusBarDarkFont(true)
            statusBarColor(R.color.white)
            titleBarMarginTop(binding.root)
        }
    }

    override fun showLoading(msg: String) {
        if(isShowing){
            super.showLoading(msg)
        }

    }

    override fun dismissLoading() {
        if(isShowing) {
            super.dismissLoading()
        }
    }

}